# _*_ encoding:utf-8 _*_

from rest_framework.viewsets import ReadOnlyModelViewSet
from rest_framework.mixins import UpdateModelMixin
from rest_framework.permissions import IsAdminUser

from orders.models import OrderInfo
from meiduo_admin.serializers.order_serializers import OrderSimpleModelSerialize, OrderDetailModelSerialize
from meiduo_admin.paginations import MyPage
from meiduo_mall.utils.django_drf_filter import get_filter


class OrderView(UpdateModelMixin, ReadOnlyModelViewSet):

    permission_classes = [IsAdminUser]

    queryset = OrderInfo.objects.all()
    serializer_class = OrderSimpleModelSerialize
    pagination_class = MyPage
    filter_class = get_filter(OrderInfo, 'order_id')  # 指定过滤器

    def get_serializer_class(self):

        if self.action == 'retrieve':
            return OrderDetailModelSerialize

        return self.serializer_class


